﻿namespace Amazon.Checkout.Drivers
{
    using JetBrains.Annotations;
    using Models;

    using Orchard;
    using Orchard.ContentManagement;
    using Orchard.ContentManagement.Drivers;

    [UsedImplicitly]
    public class ShoppingCartPartDriver : ContentPartDriver<ShoppingCartPart> 
    {
        private readonly IOrchardServices orchardServices;

        public ShoppingCartPartDriver(IOrchardServices orchardServices)
        {
            this.orchardServices = orchardServices;
        }

        protected override DriverResult Display(ShoppingCartPart part, string displayType, dynamic shapeHelper)
        {
            var currentSite = this.orchardServices.WorkContext.CurrentSite;
            var settings = currentSite.As<SiteSettingsPart>();

            return ContentShape(
                "Parts_ShoppingCart", 
                () => shapeHelper.Parts_ShoppingCart(
                                        TemplateName: "ShoppingCart", 
                                        ContentPart: part, 
                                        AmazonButtonInitialized: !string.IsNullOrEmpty(settings.MerchantId),
                                        Settings: settings));
        }
    }
}